#include "Piece.h"
#include "Board.h"
#include "Vector.hpp"
#include "DirectInput.h"
#include "Button.h"
#include "Sound.h"

// the different states that the game engine can go through

struct Player
{
	Vector<Piece*>	myPieces;			// the pieces that the player has yet to play
	int				myScore;			// the player's score
	bool			firstTurn;			// whether or not the player is on his first turn
	int				passes;				// number of times this player has chosen to skip his turn
};
enum eGameState
{
	SELECTION,
	PLACEMENT,
	GAMEOVER
};
const int numPieces = 21;

// this is the main game engine. It will handle all of the objects and their respective update functions
class Game
{
private:
	Player			m_Players[2];		// the two players
	int				activePlayer;		// the index of the current player
	int				selectionIndex;		// which piece the current player has selected
	bool			m_displayInstructions;

	// the coordinates for where the players' pieces start (outside the board)
	const int P1XStart;
	const int P1YStart;
	const int P2XStart;
	const int P2YStart;

	const int pieceRows;				// the number of rows one player's pieces are arranged into
	const int pieceColumns;				// number of columns one player's pieces are arranged into
	const int xSpacing;					// how far pieces are spaced apart horizontally
	const int zSpacing;					// how far pieces are spaced apart vertically

	// the different camera positions
	Vec3D			m_v3P1PieceView;
	Vec3D			m_v3P1TopDownView;
	Vec3D			m_v3P2PieceView;
	Vec3D			m_v3P2TopDownView;

	TextBox*		pGuideText;			// displays helpful information like instructions to the screen
	TextBox*		pP1Score;			// displays player 1's score
	TextBox*		pP2Score;			// displays player 2's score

	Button*			pPassButton;		// let's the player skip his turn

	Drawable*		pCamera;

	Board			m_theBoard;			// the board handler
	Game();


	// private functions for use internally within Game
	void StartNewGame();
	void Selection(Player & player, int & selectionIndex);
	bool Placement(Piece* pPiece);
	void ReturnPiece(int playerIndex, int selectionIndex);
	void PlaceStartingPiece(Piece* pPiece, int player);
	void HandleSelectionInput();

public:
	static inline Game* Engine()
	{static Game g; return &g;}

	eGameState theState;
	bool Init();
	Vector<Piece*>	  getPieces();		// collects a list of one of each piece
	Vector<Drawable*> getDrawables();	// collects a list of all drawable objects
	Vector<TextBox*>  getTextBoxes();	// collects a list of textboxes
	bool Update();
	void Release();
	~Game();
};